package cn.yuyin.item;

import javax.microedition.lcdui.Graphics;

import cn.yuyin.main.Main;
import cn.yuyin.page.ListForm;
import cn.yuyin.utile.GraduaChange;

public class Select extends Item{

	public ListForm listForm;
	public Select(int index,int x, int y, String text ,ListForm listForm) {
		super(x, y, text);
		this.index = index;
		this.listForm = listForm;
		width = Main.font.stringWidth(text)+2*Main.margin+20;
		if((x+width+30)>Main.WIDTH){
			width = Main.font.stringWidth(text)+2*Main.margin;
		}
		height = Main.font.getHeight()+4;
		endX = x+width;
		endY = y;
		listForm.select = this;
	}
	
	public Select(int index,int x, int y, String text ,Select select,ListForm listForm) {
		super(x, y, text);
		this.index = index;
		this.listForm = listForm;
		width = Main.font.stringWidth(text)+2*Main.margin+20;
		height = Main.font.getHeight()+4;
		endX = x+width;
		endY = y;
		listForm.select = this;
		listForm.select2 = select;
	}

	public Select(int index,int x, int y, String text ,ListForm listForm,int width) {
		super(x, y, text);
		this.index = index;
		this.listForm = listForm;
		this.width=width;
		height = Main.font.getHeight()+4;
		endX = x+width;
		endY = y;
		listForm.select = this;
	}
	
	public void paint(Graphics g) {
		if(index == Main.superPage.index){
			ishaveFouse = true;
		}else{
			ishaveFouse = false;
		}
		int color = g.getColor();
		if(ishaveFouse){
			
			GraduaChange.DrawList(g,x, y, width, height, 0xDDDDDD,0xDDDDDD);
			g.setColor(0x6A6A6A);
			g.drawRoundRect(x, y, width, height, 10, 10);
			g.setColor(0x6A6A6A);
			g.drawRoundRect(x, y, width, height, 9, 9);
			g.setColor(0);
			
			g.drawString(text, x+width/2-Main.font.stringWidth(text)/2, y+height/2-Main.font.getHeight()/2, 0);
			//g.drawString(text, x+Main.margin, y+2, 0);
//			g.setColor(0xEFEFEF);
//			g.fillRect(x+width-20, y, 20, height);
//			g.setColor(0x6A6A6A);
//			g.drawRoundRect(x+width-20, y, 20, height, 4, 4);
//			g.setColor(0x6A6A6A);
//			g.fillTriangle(x+width-17, y+height/4, x+width-2, y+height/4, x+width-10, y+height/4+8);
			
		}else{
			GraduaChange.DrawList(g,x, y, width, height, 0xFFFFFF,0xD3D3D3);
			g.setColor(0x6A6A6A);
			g.drawRoundRect(x, y, width+1, height, 10, 10);
			g.setColor(0x6A6A6A);
			g.drawRoundRect(x, y, width+1, height, 9, 9);
			g.setColor(0);
			g.drawString(text, x+width/2-Main.font.stringWidth(text)/2, y+height/2-Main.font.getHeight()/2, 0);
			//g.drawString(text, x+Main.margin, y+2, 0);
//			g.setColor(0xEFEFEF);
//			g.fillRect(x+width-20, y, 20, height);
//			g.setColor(0x6A6A6A);
//			g.drawRoundRect(x+width-20, y, 20, height, 4, 4);	
//			g.setColor(0);
//			g.fillTriangle(x+width-17, y+height/4, x+width-2, y+height/4, x+width-10, y+height/4+8);
			
		}
		
		g.setColor(color);
	}

	public void keyPressed(int keyCode) {
		// TODO Auto-generated method stub
		
	}

	public void keyReleased(int keyCode) {
		switch (keyCode) {
		case Main.key_OK:
			if(ishaveFouse){
				Main.display.setCurrent(listForm);
			}
			break;
		}
	}

	public void pointerPressed(int x, int y) {
		Main.display.setCurrent(listForm);		
	}

	public void pointerReleased(int x, int y) {
		
	}

}
